package com.xdf.ecommerce.service.communication;

import com.xdf.ecommerce.service.communication.hystrix.AuthorityFeignClientFallback;
import com.xdf.ecommerce.service.communication.hystrix.AuthorityFeignClientFallbackFactory;
import com.xdf.ecommerce.vo.JwtToken;
import com.xdf.ecommerce.vo.UsernameAndPassword;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 注意注解 @FeignClient 中的 value 应该填写微服务的名称(spring.application.name)，不是微服务模块的 server.servlet.context-path
 * 说明本实例与微服务 e-commerce-authority-center 进行通信
 * 显式的设置 contextId 后可以制作多个同微服务 e-commerce-authority-center 通信的 interface
 * 相反，如果不指定 contextId，则一个模块中针对微服务 e-commerce-authority-center 只能制作一个 interface
 * @author chanchaw
 * @create 2025-10-29 12:18
 */
//@FeignClient(contextId = "AuthorityFeignClient", value = "e-commerce-authority-center", fallback = AuthorityFeignClientFallback.class)
@FeignClient(contextId = "AuthorityFeignClient", value = "e-commerce-authority-center", fallbackFactory = AuthorityFeignClientFallbackFactory.class)
public interface AuthorityFeignClient {
    /**
     * 注意注解 @RequestMapping 中填写的是 server.servlet.context-path，不是 spring.application.name
     * 在使用 openFeign 的原生 API 时才需要设置 consumes 和 produces
     * 所以常规使用时，不要设置这两个属性
     * @param usernameAndPassword
     * @return
     */
    @RequestMapping(value = "/ecommerce-authority-center/authority/token", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
    JwtToken getToken(@RequestBody UsernameAndPassword usernameAndPassword);
}
